<?php
namespace app\user\controller;
use think\Db;
use think\view;
use think\controller;
use app\user\model\User;

class Regis extends Base
{
    public function usregis()
    {
        $view = new View();
        return $view->fetch();
    }

    // 注册功能
    public function zhuce()
    {
        //实例化User
        $user = new User;
        //接收前端表单提交的数据
        $user->name = input('post.username');
        $user->password = md5(input('post.UserPasswd'));
        $user->email = input('post.UserEmail');
        //进行规则验证
        $result = $this->validate(
            [
                'name' => $user->name,
                'password' => $user->password,
                'email' => $user->email,
            ],
            [
                'name' => 'require|max:10',
                'password' => 'require',
                'email' => 'email',
            ]);
        if (true !== $result) {
            $this->error($result);
        }

        //写入数据库
        $data = ['name' => $user->name,
            'password' => md5($user->password),
            'email' => $user->email,
        ];
        $res = db('ole_users')->insert($data);
        if ($res==1) {
            return $this->success('注册成功','login/loginn');
        } else {
            return $this->success('注册失败');
        }



    }
}